
 /*******************************************************************************************
 *                                                                                          *
 * File Name   : ComStack_Types.h                                                           *
 *                                                                                          *
 * Author      : ITI AUTOSAR CanTP Team                                                     *
 *                                                                                          *
 * Platform    : TivaC                                                                      *
 *                                                                                          *
 * Date        : 5 Jun 2020	                                                                *
 *                                                                                          *
 * Version	   : 4.0.0                                                                      *
 *                                                                                          *
 * Description : specifies the AUTOSAR communication stack type header file Release 4.3.1   *
 *                                                                                          *
 ********************************************************************************************/

#ifndef COMSTACK_TYPES_H_
#define COMSTACK_TYPES_H_


#include "Std_Types.h"
//#include "include/ComStack_Cfg.h"

/* This type is used within the entire AUTOSAR Com Stack except for bus drivers
 * Zero-based integer number The size of this global type depends on the maximum number of PDUs used within one software module.
 * This parameter shall be generated by the generator tool depending on the value configured in EcuC virtual layer.
 * This parameter shall be generated in ComStack_Cfg.h file
 * Example : If '''no''' software module deals with more PDUs that 256, this type can be set to uint8.
 * If at least one software module handles more than 256 PDUs, this type must globally be set to uint16
 */
typedef uint16 PduIdType         ;


/* This type shall be used within the entire AUTOSAR Com Stack of an ECU except for bus drivers
 * Zero-based integer number The size of this global type depends on the maximum length of PDUs to be sent by an ECU.
 * This parameter shall be generated by the generator tool depending on the value configured in EcuC virtual layer.
 * This parameter shall be generated in ComStack_Cfg.h file
 * Example : If no segmentation is used the length depends on the maximum payload size of a frame of the underlying communication system
 * (for FlexRay maximum size is 255, therefore uint8).
 * If segmentation is used it depends on the maximum length of a segmented N-PDU (in general uint16 is used)
 */
typedef uint32 PduLengthType     ;


/* Used to store the identifier of a partial network cluster */
typedef uint8  PNCHandleType     ;


/* Specify the parameter to which the value has to be changed (BS or STmin) in TP Protocol
 * Range:-
 *            1.TP_STMIN
              2.TP_BS
              3.TP_BC
 */
typedef uint8  TPParameterType   ;


/* Variables of this type shall be used to store the result of a buffer request
 * Range:-
 *            1.BUFREQ_OK
              2.BUFREQ_E_NOT_OK
              3.BUFREQ_E_BUSY
              4.BUFREQ_E_OVFL
 */
typedef uint8  BufReq_ReturnType ;


/* Variables of this type shall be used to store the state of TP buffer
 * Range:-
 *            1.TP_DATACONF
              2.TP_DATARETRY
              3.TP_CONFPENDING
 */
typedef uint8  TpDataStateType   ;


/* Variables of the type NetworkHandleType shall be used to store the identifier of a communication channel, Range 0:255 */
typedef uint8  NetworkHandleType ;


/* IcomConfigIdType defines the configuration ID. An ID of 0 is the default configuration.
 * An ID greater than 0 shall identify a configuration for Pretended Networking. There is more than 1 configuration possible
 */
typedef uint8  IcomConfigIdType;


/* IcomSwitch_ErrorType defines the errors which can occur when activating or deactivating Pretended Networking
 * Range:-
 *            1.ICOM_SWITCH_E_OK
              2.ICOM_SWITCH_E_FAILED
 */
typedef uint8  IcomSwitch_ErrorType ;


/* Separation Time (STmin) */
#define TP_STMIN           (TPParameterType)0x00
/* Block Size (BS)*/
#define TP_BS              (TPParameterType)0x01
/* The Band width control parameter used in FlexRay transport protocol module */
#define TP_BC              (TPParameterType)0x02


/* Buffer request accomplished successful. This status shall have the value 0 */
#define BUFREQ_OK          (BufReq_ReturnType)0x00
/* Buffer request not successful. Buffer cannot be accessed. This status shall have the value 1 */
#define BUFREQ_E_NOT_OK    (BufReq_ReturnType)0x01
/* Temporarily no buffer available. It's up the requester to retry request for a certain time. This status shall have the value 2 */
#define BUFREQ_E_BUSY      (BufReq_ReturnType)0x02
/* No Buffer of the required length can be provided. This status shall have the value 3 */
#define BUFREQ_E_OVFL      (BufReq_ReturnType)0x03


/* TP_DATACONF indicates that all data, that have been copied so far, are confirmed and can be removed from the TP buffer.
 * Data copied by this API call are excluded and will be confirmed later
 */
#define TP_DATACONF        (TpDataStateType)0x00
/* TP_DATARETRY indicates that this API call shall copy already copied data in order to recover from an error.
 *In this case TxTpDataCnt specifies the offset of the first byte to be copied by the API call.
 */
#define TP_DATARETRY       (TpDataStateType)0x01
/* TP_CONFPENDING indicates that the previously copied data must remain in the TP */
#define TP_CONFPENDING     (TpDataStateType)0x02


/* The activation of Pretended Networking was successful */
#define ICOM_SWITCH_E_OK      (IcomSwitch_ErrorType)0x00
/* The activation of Pretended Networking was not successful */
#define ICOM_SWITCH_E_FAILED  (IcomSwitch_ErrorType)0x01


/*
 * Variables of this type shall be used to store the basic information about a PDU of
 * any type, namely a pointer variable pointing to its SDU (payload), a pointer to
 * Meta Data of the PDU, and the corresponding length of the SDU in bytes. 
*/
typedef struct
{
/* Pointer to the SDU (i.e. payload data) of the PDU. The type of this pointer depends on the memory model being used at compile time */
	uint8*         SduDataPtr  ;
/* Pointer to the meta data (e.g. CAN ID, socket ID, diagnostic addresses) of the PDU, consisting of a sequence of meta data items.
 * The length and type of the meta data items is statically configured for each PDU.
 * Meta data items with more than 8 bits use platform byte order
 */
	uint8*         MetaDataPtr ;
/* Length of the SDU in bytes. */
	PduLengthType  SduLength   ;
}PduInfoType;



/* Variables of this type shall be used to store the information about Tp buffer handling  */
 typedef struct
{
/* The enum type to be used to store the state of Tp buffer */
    TpDataStateType TpDataState  ;
/* Offset from the current position which identifies the number of bytes to be retransmitted */
    PduLengthType   TxTpDataCnt  ;
}RetryInfoType; 


#endif /* COMSTACK_TYPES_H_ */
